package com.example.final_project.Internet;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

import androidx.annotation.NonNull;

import com.ejlchina.okhttps.OkHttps;
import com.example.final_project.Cate.Activity.CateCarActivity;
import com.example.final_project.Cate.entry.CateCars;
import com.example.final_project.Home.entry.CarNews;
import com.example.final_project.Usr.entry.UserStore;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Internet {

    private volatile static Internet internet;
    private static final int STORE=0;
    private List<UserStore> userStores;

    private Internet(){}

    public static synchronized Internet getInstance(){

        //第一次判空
        if(internet == null){
            synchronized (Internet.class){
                //第二次判空
                if(internet == null){
                    internet = new Internet();
                }
            }
        }
        return internet;
    }


    public List<UserStore> getStoreTag(int id){
        OkHttps.async("http://10.150.11.9:8086/chengcar/storeid")
                .bind(this)
                .addUrlPara("id", id)
                .setOnResList(UserStore.class, store -> {
                    Message message = Message.obtain();
                    message.what = STORE;
                    userStores = store;
                })
                .get();
        return userStores;
    }

}
